from django.contrib import admin
from feedbag.apps.product.models import Brand, Product, ProductType, \
	ProductImage, ProductNutrition, Review

class BrandAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
admin.site.register(Brand, BrandAdmin)

class ProductTypeAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
admin.site.register(ProductType, ProductTypeAdmin)

class ProductNutritionInline(admin.StackedInline):
    model = ProductNutrition

class ProductAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}    
    readonly_fields = ('has_review',)
    inlines = [ProductNutritionInline]
admin.site.register(Product, ProductAdmin)

class ReviewAdmin(admin.ModelAdmin):
	def save_model(self, request, obj, form, change):
		obj.product.has_review = True
		print obj.product.has_review
		obj.product.save()
		obj.save()
		
admin.site.register(Review, ReviewAdmin)